var APP = require("../main/app");
var PAGE = require("../api/page");
var DATA = require("../data/data");
module.exports = {
	//site_exchange|id:5,name:张三|win
	//广告跳转页面
	toUrl : function(linkUrl) {
		//如果不跳转的情况
		if(!linkUrl) {
			return; 
		}
		//如果是跳转链接的情况
		if(linkUrl.indexOf('http') > -1) {
			PAGE.openUrl(linkUrl);
			return;
		}
		//其他情况，打开APP内置链接
		linkUrl = linkUrl.split('|');
		var openType = 'Win';
		if(linkUrl.length<1) {
			return;
		}
		var winName = linkUrl[0];
		var params = {};
		if(linkUrl.length>1) {
			if(linkUrl[1] && linkUrl[1] != 'none') {
				var paramsArray = linkUrl[1].split(',');
				for (var i = 0; i < paramsArray.length; i++) {
					var paramTmp = paramsArray[i].split(':');
					var _key = paramTmp[0];
					params[_key] = paramTmp[1];
				}
			} 
			if(linkUrl.length==3 && linkUrl[2] == 'frame') {
				openType = 'Frame';
			}
		}
		//打开窗口
		if(openType == 'Frame') {
			PAGE.openFrame(winName, params);
		} else {
			PAGE.openWin(winName, params);
		}
	},
	//推送检查页面
	checkPage:function(param) {
		var that = this;
		try {
			var params = {};
			if(api.systemType == 'ios') {
				params = param;
			} else {
				params = param.ajpush.extra;
			}
			
			/*
			if(params.hasOwnProperty('msg_id') && params.msg_id > 0) {
				that.readMsg(params.msg_id);
			}
			 */
			
			that.checkExtra(params);
			
		} catch(e) {}
	},
	//检查参数
	checkExtra:function(params) {
		try {
			if(params.type == 'url') {
				if(params.url.indexOf('http://') > -1) {
					WIN.openUrl(params.url);
				} else if(params.url.indexOf('app.') > -1) {
					var method = params.url.replace('app.', 'WIN.');
					eval(method);
				}
			} else if(params.type == 'event') {
				
			}
		}  catch(e) {}
	},
}